﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Drawing;
using MediaPortal.GUI.Library;
using MediaPortal.Configuration;
using MediaPortal.Dialogs;
using System.Threading;

namespace MyNetflix2
{
    public class ItemProcessor: GUIWindow
    {
        #region Includes

        [DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
        public static extern IntPtr FindWindow(string lpClassName,
            string lpWindowName);

        // Activate an application window.
        [DllImport("USER32.DLL")]
        public static extern bool SetForegroundWindow(IntPtr hWnd);

        [DllImport("user32.dll", EntryPoint = "SetWindowPos")]
        public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);

        #endregion

        #region Locals

        public Connection _conn = new Connection();
        [SkinControlAttribute(50)]
        public GUIFacadeControl _facadeQueue = null;
        [SkinControlAttribute(9)]
        protected GUILabelControl _dummyLabel = null;
        public MyNetFlixMain.FacadeView _currentView;
        protected List<List<GUIListItem>> _facadeQueueHold = new List<List<GUIListItem>>();
        protected List<int> _facadeSelectedIndexHold = new List<int>();
        protected List<MyNetFlixMain.FacadeView> _facadeSelectedViewHold = new List<MyNetFlixMain.FacadeView>();
        public List<string> _queueUsers = new List<string>();
        public List<string> _instantUsers = new List<string>();
        public User _user = null;
        protected List<Queue> _myQueues = new List<Queue>();
        protected Queue _myQueue = null;
        protected List<string> _lstWatchedMovies = new List<string>();
 
        #endregion

        #region Constructor

        /// <summary>
        /// Constructor
        /// </summary>
        public ItemProcessor()
        {
            _lstWatchedMovies = _conn.GetWatchedMovies();
        }

        #endregion

        #region Process Items

        /// <summary>
        /// If the Disc Queue button is pressed lets get the items in the queue and display them
        /// </summary>
        public GUIListItem ProcessItem(QueueItem item, MyNetFlixMain.FacadeView view)
        {
            string sTitle = "";

            if (item.AltTitle != "")
                sTitle = item.AltTitle;
            else if (item.ShortTitle != "")
                sTitle = item.ShortTitle;
            else
                sTitle = item.Title;

            try
            {
                GUIListItem thisItem = new GUIListItem(sTitle);

                //-------------------------------------------------------------------------------------------------
                // Lets find the proper icon to display with the movie.
                //-------------------------------------------------------------------------------------------------
                string image = "";

                if (item.IsDvd && item.IsBluRay && item.IsInstant)
                    image = "all.png";
                else if (item.IsDvd && item.IsBluRay && !item.IsInstant)
                    image = "dvd_bluray.png";
                else if (item.IsDvd && !item.IsBluRay && !item.IsInstant)
                    image = "dvd.png";
                else if (item.IsDvd && !item.IsBluRay && item.IsInstant)
                    image = "dvd_instant.png";
                else if (!item.IsDvd && item.IsBluRay && item.IsInstant)
                    image = "bluray_instant.png";
                else if (!item.IsDvd && item.IsBluRay && !item.IsInstant)
                    image = "bluray.png";
                else if (!item.IsDvd && !item.IsBluRay && item.IsInstant)
                    image = "instant.png";

                //-------------------------------------------------------------------------------------------------
                // Show the TV icon if its a TV series, but not on the Season & Episodes listings
                //-------------------------------------------------------------------------------------------------
                if (item.IsSeries && !item.IsEpisode && !(view == MyNetFlixMain.FacadeView.Season))
                    image = "s" + image;

                //-------------------------------------------------------------------------------------------------
                // Lets now find the cover art for the movie/series
                //-------------------------------------------------------------------------------------------------
                thisItem.PinImage = image;

                thisItem.ThumbnailImage = Config.GetFolder(Config.Dir.Thumbs) + "\\MyNetFlix\\Covers\\" + (item.CoverId) + ".jpg";
                thisItem.OnItemSelected += new MediaPortal.GUI.Library.GUIListItem.ItemSelectedHandler(OnItemSelected);
                thisItem.TVTag = item;

                return thisItem;
            }
            catch (Exception ex)
            {
                Log.Error("My NetFlix - ItemProcessor:ProcessItem: Error setting list item: " + ex.Message);
                return null;
            }
        }

        /// <summary>
        /// If the Disc Queue button is pressed lets get the items in the queue and display them
        /// </summary>
        public GUIListItem ProcessItem(ODataItem item, MyNetFlixMain.FacadeView view)
        {
            string sTitle = "";
                sTitle = item.Title;

            try
            {
                GUIListItem thisItem = new GUIListItem(sTitle);

                //-------------------------------------------------------------------------------------------------
                // Lets find the proper icon to display with the movie.
                //-------------------------------------------------------------------------------------------------
                string image = "";

                if (item.IsDvd && item.IsBluRay && item.IsInstant)
                    image = "all.png";
                else if (item.IsDvd && item.IsBluRay && !item.IsInstant)
                    image = "dvd_bluray.png";
                else if (item.IsDvd && !item.IsBluRay && !item.IsInstant)
                    image = "dvd.png";
                else if (item.IsDvd && !item.IsBluRay && item.IsInstant)
                    image = "dvd_instant.png";
                else if (!item.IsDvd && item.IsBluRay && item.IsInstant)
                    image = "bluray_instant.png";
                else if (!item.IsDvd && item.IsBluRay && !item.IsInstant)
                    image = "bluray.png";
                else if (!item.IsDvd && !item.IsBluRay && item.IsInstant)
                    image = "instant.png";

                //-------------------------------------------------------------------------------------------------
                // Show the TV icon if its a TV series, but not on the Season & Episodes listings
                //-------------------------------------------------------------------------------------------------
                if (item.IsSeries && !item.IsEpisode && !(view == MyNetFlixMain.FacadeView.Season))
                    image = "s" + image;
                
                //-------------------------------------------------------------------------------------------------
                // Lets now find the cover art for the movie/series
                //-------------------------------------------------------------------------------------------------
                thisItem.PinImage = image;

                thisItem.ThumbnailImage = Config.GetFolder(Config.Dir.Thumbs) + "\\MyNetFlix\\Covers\\" + (item.CoverId) + ".jpg";
                thisItem.OnItemSelected += new MediaPortal.GUI.Library.GUIListItem.ItemSelectedHandler(OnODataItemSelected);
                thisItem.TVTag = item;

                return thisItem;
            }
            catch (Exception ex)
            {
                Log.Error("My NetFlix - ItemProcessor:ProcessItem: Error setting list item: " + ex.Message);
                return null;
            }
        }

        /// <summary>
        /// If the Disc Queue button is pressed lets get the items in the queue and display them
        /// </summary>
        public GUIListItem ProcessRSSItem(ODataItem item, MyNetFlixMain.FacadeView view)
        {
            string sTitle = "";
            sTitle = item.Title;

            try
            {
                GUIListItem thisItem = new GUIListItem(sTitle);

                //-------------------------------------------------------------------------------------------------
                // Lets find the proper icon to display with the movie.
                //-------------------------------------------------------------------------------------------------
                thisItem.ThumbnailImage = Config.GetFolder(Config.Dir.Thumbs) + "\\MyNetFlix\\Covers\\" + (item.CoverId) + ".jpg";
                thisItem.OnItemSelected += new MediaPortal.GUI.Library.GUIListItem.ItemSelectedHandler(OnRSSItemSelected);
                thisItem.TVTag = item;

                return thisItem;
            }
            catch (Exception ex)
            {
                Log.Error("My NetFlix - ItemProcessor:ProcessRSSItem: Error setting list item: " + ex.Message);
                return null;
            }
        }

        /// <summary>
        /// If a list item is set to OnItemSelected, it will set certain properties when a selection is made
        /// </summary>
        public void OnItemSelected(GUIListItem item, GUIControl parent)
        {
            QueueItem info = (QueueItem)item.TVTag;

            try
            {
                Thread.Sleep(250);
                if (_facadeQueue.SelectedListItem.Label != info.Title && _facadeQueue.SelectedListItem.Label != info.ShortTitle && _facadeQueue.SelectedListItem.Label != info.AltTitle)
                    return;


                info = (QueueItem)item.TVTag;

                //-------------------------------------------------------------------------------------------------
                // Set the base properties... runtime, rating, ratings
                //-------------------------------------------------------------------------------------------------
                GUIPropertyManager.SetProperty("#movieruntime", info.RunTime + " Min");
                GUIPropertyManager.SetProperty("#movierated", info.Ratings[0].ToString());
                decimal starRating = decimal.Parse(info.AverageRating) * 2;
                GUIPropertyManager.SetProperty("#starrating", starRating.ToString());
                GUIPropertyManager.SetProperty("#movietitle", info.ShortTitle != "" ? info.ShortTitle : info.Title);
                GUIPropertyManager.SetProperty("#year", info.ReleaseYear.ToString());
                GUIPropertyManager.SetProperty("#synopsis", info.Synopsis);

                //-------------------------------------------------------------------------------------------------
                // Get the coverart and the back drop images
                //-------------------------------------------------------------------------------------------------
                string filename = Config.GetFolder(Config.Dir.Thumbs) + "\\MyNetFlix\\Covers\\" + info.CoverId + ".jpg";
                string filenameBD = Config.GetFolder(Config.Dir.Thumbs) + "\\MyNetFlix\\BackDrops\\" + info.BackDropId + ".jpg";

                //-------------------------------------------------------------------------------------------------
                // Show the icons for the appropriate format availability
                //-------------------------------------------------------------------------------------------------
                if (info.IsBluRay)
                    GUIPropertyManager.SetProperty("#blurayvideo", "True");
                else
                    GUIPropertyManager.SetProperty("#blurayvideo", "");

                if (info.IsDvd)
                    GUIPropertyManager.SetProperty("#dvdvideo", "True");
                else
                    GUIPropertyManager.SetProperty("#dvdvideo", "");

                if (info.IsInstant)
                    GUIPropertyManager.SetProperty("#instantvideo", "True");
                else
                    GUIPropertyManager.SetProperty("#instantvideo", "");

                if (info.Availability != "")
                    GUIPropertyManager.SetProperty("#availability", info.Availability);
                else
                    GUIPropertyManager.SetProperty("#availability", "");


                if (!File.Exists(filename))
                    GUIPropertyManager.SetProperty("#detailcover", Config.GetFolder(Config.Dir.Thumbs) + "\\MyNetFlix\\Covers\\" + info.CoverId + ".jpg");
                else
                {
                    Image img = Image.FromFile(filename);
                    if ((img.Width / img.Height) < 1)
                    {
                        GUIPropertyManager.SetProperty("#detailcover", filename);
                        GUIPropertyManager.SetProperty("#episodecover", "");
                    }
                    else
                    {
                        GUIPropertyManager.SetProperty("#detailcover", "");
                        GUIPropertyManager.SetProperty("#episodecover", filename);
                    }
                }


                if (!File.Exists(filenameBD))
                    GUIPropertyManager.SetProperty("#detailBackground", "");
                else
                    GUIPropertyManager.SetProperty("#detailBackground", filenameBD);


            }
            catch (Exception ex)
            {
                Log.Info("My NetFlix - ItemProcessor:item_OnItemSelected: Error Retreiving info for " + info.CoverId + " : Error" + ex.Message);
            }
        }

        /// <summary>
        /// If a list item is set to OnItemSelected, it will set certain properties when a selection is made
        /// </summary>
        public void OnODataItemSelected(GUIListItem item, GUIControl parent)
        {
            string coverId = "";

            try
            {
                ODataItem info = (ODataItem)item.TVTag;
                coverId = info.CoverId;

                Thread.Sleep(250);
                if (_facadeQueue.SelectedListItem.Label != info.Title && _facadeQueue.SelectedListItem.Label != info.ShortTitle && _facadeQueue.SelectedListItem.Label != info.AltTitle)
                    return;

                //-------------------------------------------------------------------------------------------------
                // Set the base properties... runtime, rating, ratings
                //-------------------------------------------------------------------------------------------------
                GUIPropertyManager.SetProperty("#movieruntime", info.RunTime + " Min");
                GUIPropertyManager.SetProperty("#movierated", info.Ratings[0].ToString());
                decimal starRating = decimal.Parse(info.AverageRating) * 2;
                GUIPropertyManager.SetProperty("#starrating", starRating.ToString());
                GUIPropertyManager.SetProperty("#movietitle", info.Title);
                GUIPropertyManager.SetProperty("#year", info.ReleaseYear.ToString());
                GUIPropertyManager.SetProperty("#synopsis", info.Synopsis);

                //-------------------------------------------------------------------------------------------------
                // Get the coverart and the back drop images
                //-------------------------------------------------------------------------------------------------
                string filename = Config.GetFolder(Config.Dir.Thumbs) + "\\MyNetFlix\\Covers\\" + info.CoverId + ".jpg";
                string filenameBD = Config.GetFolder(Config.Dir.Thumbs) + "\\MyNetFlix\\BackDrops\\" + info.CoverId + ".jpg";

                //-------------------------------------------------------------------------------------------------
                // Show the icons for the appropriate format availability
                //-------------------------------------------------------------------------------------------------
                if (info.IsBluRay)
                    GUIPropertyManager.SetProperty("#blurayvideo", "True");
                else
                    GUIPropertyManager.SetProperty("#blurayvideo", "");

                if (info.IsDvd)
                    GUIPropertyManager.SetProperty("#dvdvideo", "True");
                else
                    GUIPropertyManager.SetProperty("#dvdvideo", "");

                if (info.IsInstant)
                    GUIPropertyManager.SetProperty("#instantvideo", "True");
                else
                    GUIPropertyManager.SetProperty("#instantvideo", "");

                if (info.Availability != "")
                    GUIPropertyManager.SetProperty("#availability", info.Availability);
                else
                    GUIPropertyManager.SetProperty("#availability", "");


                if (!File.Exists(filename))
                    GUIPropertyManager.SetProperty("#detailcover", Config.GetFolder(Config.Dir.Thumbs) + "\\MyNetFlix\\Covers\\" + info.CoverId + ".jpg");
                else
                {
                    Image img = Image.FromFile(filename);
                    if ((img.Width / img.Height) < 1)
                    {
                        GUIPropertyManager.SetProperty("#detailcover", filename);
                        GUIPropertyManager.SetProperty("#episodecover", "");
                    }
                    else
                    {
                        GUIPropertyManager.SetProperty("#detailcover", "");
                        GUIPropertyManager.SetProperty("#episodecover", filename);
                    }
                }


                if (!File.Exists(filenameBD))
                    GUIPropertyManager.SetProperty("#detailBackground", "");
                else
                    GUIPropertyManager.SetProperty("#detailBackground", filenameBD);


            }
            catch (Exception ex)
            {
                Log.Info("My NetFlix - ItemProcessor:item_OnItemSelected: Error Retreiving info for " + coverId + " : Error" + ex.Message);
            }
        }

        /// <summary>
        /// If a list item is set to OnItemSelected, it will set certain properties when a selection is made
        /// </summary>
        public void OnRSSItemSelected(GUIListItem item, GUIControl parent)
        {
            string coverId = "";

            try
            {
                ODataItem info = (ODataItem)item.TVTag;
                coverId = info.CoverId;

                Thread.Sleep(250);
                if (_facadeQueue.SelectedListItem.Label != info.Title && _facadeQueue.SelectedListItem.Label != info.ShortTitle && _facadeQueue.SelectedListItem.Label != info.AltTitle)
                    return;

                //-------------------------------------------------------------------------------------------------
                // Set the base properties... runtime, rating, ratings
                //-------------------------------------------------------------------------------------------------
                GUIPropertyManager.SetProperty("#movietitle", info.Title);
                GUIPropertyManager.SetProperty("#synopsis", info.Synopsis);
                GUIPropertyManager.SetProperty("#movieruntime", "");
                GUIPropertyManager.SetProperty("#year", "");
                GUIPropertyManager.SetProperty("#starrating", "");
                GUIPropertyManager.SetProperty("#movierated", "");

                //-------------------------------------------------------------------------------------------------
                // Get the coverart and the back drop images
                //-------------------------------------------------------------------------------------------------
                string filename = Config.GetFolder(Config.Dir.Thumbs) + "\\MyNetFlix\\Covers\\" + info.CoverId + ".jpg";
                string filenameBD = Config.GetFolder(Config.Dir.Thumbs) + "\\MyNetFlix\\BackDrops\\" + info.CoverId + ".jpg";

                if (!File.Exists(filename))
                    GUIPropertyManager.SetProperty("#detailcover", Config.GetFolder(Config.Dir.Thumbs) + "\\MyNetFlix\\Covers\\" + info.CoverId + ".jpg");
                else
                {
                    Image img = Image.FromFile(filename);
                    if ((img.Width / img.Height) < 1)
                    {
                        GUIPropertyManager.SetProperty("#detailcover", filename);
                        GUIPropertyManager.SetProperty("#episodecover", "");
                    }
                    else
                    {
                        GUIPropertyManager.SetProperty("#detailcover", "");
                        GUIPropertyManager.SetProperty("#episodecover", filename);
                    }
                }


                if (!File.Exists(filenameBD))
                    GUIPropertyManager.SetProperty("#detailBackground", "");
                else
                    GUIPropertyManager.SetProperty("#detailBackground", filenameBD);


            }
            catch (Exception ex)
            {
                Log.Info("My NetFlix - ItemProcessor:item_OnItemSelected: Error Retreiving info for " + coverId + " : Error" + ex.Message);
            }
        }

        #endregion

        #region Misc Calls (SetFirst, SavePrevious, GetCurrentModule)

        /// <summary>
        /// Set the properites of the first item in the queue
        /// </summary>
        public void SetFirst(QueueItem info, MyNetFlixMain.FacadeView view, bool showDetail)
        {
            _currentView = view;
            _dummyLabel.Visible = showDetail;
            _facadeQueue.Focus = true;

            try
            {
                //-------------------------------------------------------------------------------------------------
                // Set the base properties... runtime, rating, ratings
                //-------------------------------------------------------------------------------------------------
                GUIPropertyManager.SetProperty("#movieof", "1");
                GUIPropertyManager.SetProperty("#moviecount", _facadeQueue.Count.ToString());
                GUIPropertyManager.SetProperty("#currentmodule", GetCurrentModule());
                GUIPropertyManager.SetProperty("#movieruntime", info.RunTime + " Min");
                GUIPropertyManager.SetProperty("#movierated", info.AverageRating);
                GUIPropertyManager.SetProperty("#movierating", info.Ratings[0].ToString());
                decimal starRating = decimal.Parse(info.AverageRating) * 2;
                GUIPropertyManager.SetProperty("#starrating", starRating.ToString());
                GUIPropertyManager.SetProperty("#movietitle", info.Title);
                GUIPropertyManager.SetProperty("#year", info.ReleaseYear.ToString());
                GUIPropertyManager.SetProperty("#synopsis", info.Synopsis);

                //-------------------------------------------------------------------------------------------------
                // Get the coverart and the back drop images
                //-------------------------------------------------------------------------------------------------
                string filename = Config.GetFolder(Config.Dir.Thumbs) + "\\MyNetFlix\\Covers\\" + info.CoverId + ".jpg";
                string filenameBD = Config.GetFolder(Config.Dir.Thumbs) + "\\MyNetFlix\\BackDrops\\" + info.BackDropId + ".jpg";

                if (!File.Exists(filenameBD))
                    GUIPropertyManager.SetProperty("#detailBackground", "");
                else
                    GUIPropertyManager.SetProperty("#detailBackground", filenameBD);

                if (!File.Exists(filename))
                    GUIPropertyManager.SetProperty("#detailcover", "");
                else
                {
                    Image img = Image.FromFile(filename);
                    if ((img.Width / img.Height) < 1)
                    {
                        GUIPropertyManager.SetProperty("#detailcover", filename);
                        GUIPropertyManager.SetProperty("#episodecover", "");
                    }
                    else
                    {
                        GUIPropertyManager.SetProperty("#detailcover", "");
                        GUIPropertyManager.SetProperty("#episodecover", filename);
                    }
                }

                //-------------------------------------------------------------------------------------------------
                // Show the icons for the appropriate format availability
                //-------------------------------------------------------------------------------------------------
                if (info.IsBluRay)
                    GUIPropertyManager.SetProperty("#blurayvideo", "True");
                else
                    GUIPropertyManager.SetProperty("#blurayvideo", "");

                if (info.IsDvd)
                    GUIPropertyManager.SetProperty("#dvdvideo", "True");
                else
                    GUIPropertyManager.SetProperty("#dvdvideo", "");

                if (info.IsInstant)
                    GUIPropertyManager.SetProperty("#instantvideo", "True");
                else
                    GUIPropertyManager.SetProperty("#instantvideo", "");

                if (info.Availability != "")
                    GUIPropertyManager.SetProperty("#availability", info.Availability);
                else
                    GUIPropertyManager.SetProperty("#availability", "");
            }
            catch (Exception ex)
            {
                //Log.Info("My NetFlix - ItemProcessor:item_OnItemSelected: Error Retreiving info for " + info.CoverId + " : Error" + ex.Message);
            }
        }

        /// <summary>
        /// Set the properites of the first item in the queue
        /// </summary>
        public void SetFirst(ODataItem info, MyNetFlixMain.FacadeView view, bool showDetail)
        {
            _currentView = view;
            _dummyLabel.Visible = showDetail;
            _facadeQueue.Focus = true;

            try
            {
                //-------------------------------------------------------------------------------------------------
                // Set the base properties... runtime, rating, ratings
                //-------------------------------------------------------------------------------------------------
                GUIPropertyManager.SetProperty("#movieof", "1");
                GUIPropertyManager.SetProperty("#moviecount", _facadeQueue.Count.ToString());
                GUIPropertyManager.SetProperty("#currentmodule", GetCurrentModule());
                if(info.RunTime == 0)
                    GUIPropertyManager.SetProperty("#movieruntime", "");
                else
                    GUIPropertyManager.SetProperty("#movieruntime", info.RunTime + " Min");

                if (info.RunTime == 0)
                    GUIPropertyManager.SetProperty("#starrating", "");
                else
                {
                     if (info.Ratings != null && info.Ratings.Count > 0)
                        GUIPropertyManager.SetProperty("#movierated", info.Ratings[0].ToString());
                    if (info.AverageRating != null)
                    {
                        decimal starRating = decimal.Parse(info.AverageRating) * 2;
                        GUIPropertyManager.SetProperty("#starrating", starRating.ToString());
                    }
                }
                GUIPropertyManager.SetProperty("#movietitle", info.Title);
                if(info.ReleaseYear > 0)
                    GUIPropertyManager.SetProperty("#year", info.ReleaseYear.ToString());
                else
                    GUIPropertyManager.SetProperty("#year", "");

                GUIPropertyManager.SetProperty("#synopsis", info.Synopsis);

                //-------------------------------------------------------------------------------------------------
                // Get the coverart and the back drop images
                //-------------------------------------------------------------------------------------------------
                string filename = Config.GetFolder(Config.Dir.Thumbs) + "\\MyNetFlix\\Covers\\" + info.CoverId + ".jpg";
                string filenameBD = Config.GetFolder(Config.Dir.Thumbs) + "\\MyNetFlix\\BackDrops\\" + info.CoverId + ".jpg";

                if (!File.Exists(filenameBD))
                    GUIPropertyManager.SetProperty("#detailBackground", "");
                else
                    GUIPropertyManager.SetProperty("#detailBackground", filenameBD);

                if (!File.Exists(filename))
                    GUIPropertyManager.SetProperty("#detailcover", "");
                else
                {
                    Image img = Image.FromFile(filename);
                    if ((img.Width / img.Height) < 1)
                    {
                        GUIPropertyManager.SetProperty("#detailcover", filename);
                        GUIPropertyManager.SetProperty("#episodecover", "");
                    }
                    else
                    {
                        GUIPropertyManager.SetProperty("#detailcover", "");
                        GUIPropertyManager.SetProperty("#episodecover", filename);
                    }
                }

                //-------------------------------------------------------------------------------------------------
                // Show the icons for the appropriate format availability
                //-------------------------------------------------------------------------------------------------
                if (info.IsBluRay)
                    GUIPropertyManager.SetProperty("#blurayvideo", "True");
                else
                    GUIPropertyManager.SetProperty("#blurayvideo", "");

                if (info.IsDvd)
                    GUIPropertyManager.SetProperty("#dvdvideo", "True");
                else
                    GUIPropertyManager.SetProperty("#dvdvideo", "");

                if (info.IsInstant)
                    GUIPropertyManager.SetProperty("#instantvideo", "True");
                else
                    GUIPropertyManager.SetProperty("#instantvideo", "");

                if (info.Availability != "")
                    GUIPropertyManager.SetProperty("#availability", info.Availability);
                else
                    GUIPropertyManager.SetProperty("#availability", "");
            }
            catch (Exception ex)
            {
                //Log.Info("My NetFlix - ItemProcessor:item_OnItemSelected: Error Retreiving info for " + info.CoverId + " : Error" + ex.Message);
            }
        }

        /// <summary>
        /// Save the previous queue
        /// </summary>
        /// <param name="priorListItem"></param>
        /// <param name="priorIndex"></param>
        /// <param name="priorView"></param>
        public void SavePrevious(GUIFacadeControl priorFacade, int priorIndex, MyNetFlixMain.FacadeView priorView)
        {
            List<GUIListItem> listItems = new List<GUIListItem>();

            //----------------------------------------------------------------------------------------------
            // save the items in the facade control
            //----------------------------------------------------------------------------------------------
            for (int i = 0; i < priorFacade.Count; i++)
            {
                listItems.Add(priorFacade[i]);
            }

            //----------------------------------------------------------------------------------------------
            // Now add the items to the hold variables
            //----------------------------------------------------------------------------------------------
            _facadeQueueHold.Add(listItems);
            _facadeSelectedIndexHold.Add(priorIndex);
            _facadeSelectedViewHold.Add(priorView);

            //----------------------------------------------------------------------------------------------
            // Clear the queue for the new load
            //----------------------------------------------------------------------------------------------
            _facadeQueue.Clear();
        }

        /// <summary>
        /// Return the current module for display in the skin
        /// </summary>
        /// <returns></returns>
        private string GetCurrentModule()
        {
            string currentModule = "";

            switch (_currentView)
            {
                case MyNetFlixMain.FacadeView.Users:
                    currentModule = "Pick a User";
                    break;
                case MyNetFlixMain.FacadeView.Disc:
                    currentModule = "Disc Queue";
                    break;
                case MyNetFlixMain.FacadeView.Discs:
                    currentModule = "Series View";
                    break;
                case MyNetFlixMain.FacadeView.Season:
                    currentModule = "Series View";
                    break;
                case MyNetFlixMain.FacadeView.Episode:
                    currentModule = "Series Episodes";
                    break;
                case MyNetFlixMain.FacadeView.Recommendations:
                    currentModule = "Recommendations";
                    break;
                case MyNetFlixMain.FacadeView.Home:
                    currentModule = "Pick a Category";
                    break;
                case MyNetFlixMain.FacadeView.InstantDetail:
                    currentModule = "Instant Queue";
                    break;
                case MyNetFlixMain.FacadeView.InstantMenu:
                    currentModule = "Instant Menu";
                    break;
                case MyNetFlixMain.FacadeView.OData:
                    currentModule = "Search Query";
                    break;
                case MyNetFlixMain.FacadeView.RentalHistoryAll:
                    currentModule = "All Rental History";
                    break;
                case MyNetFlixMain.FacadeView.RentalHistoryReceived:
                    currentModule = "Rental History Received";
                    break;
                case MyNetFlixMain.FacadeView.RentalHistoryShipped:
                    currentModule = "Rental History Shipped";
                    break;
                case MyNetFlixMain.FacadeView.RentalHistoryWatched:
                    currentModule = "Rental History Watched";
                    break;
                case MyNetFlixMain.FacadeView.RentalMenu:
                    currentModule = "Pick a Category";
                    break;
                case MyNetFlixMain.FacadeView.RSS:
                    currentModule = "NetFlix Top Picks";
                    break;
            }

            GUIPropertyManager.SetProperty("#currentmodule", currentModule);
            return currentModule;
        }

        /// <summary>
        /// Notify the user messagebox
        /// </summary>
        /// <param name="header"></param>
        /// <param name="message"></param>
        public void NotifyUser(string header, string message)
        {
            GUIDialogNotify dlgNotify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY);
            if (null != dlgNotify)
            {
                dlgNotify.TimeOut = 5;
                dlgNotify.SetHeading(header);
                dlgNotify.SetText(message);
                dlgNotify.DoModal(GUIWindowManager.ActiveWindow);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public void SetView(MyNetFlixMain.FacadeView view)
        {
            _currentView = view;

            if (view == MyNetFlixMain.FacadeView.Home)
            {
                _facadeQueue.View = GUIFacadeControl.ViewMode.List;
            }
            else
            {
                switch (_conn.GetMyView(view))
                {
                    case -1:
                        _facadeQueue.View = GUIFacadeControl.ViewMode.List;
                        break;
                    case 1:
                        _facadeQueue.View = GUIFacadeControl.ViewMode.List;
                        break;
                    case 2:
                        _facadeQueue.View = GUIFacadeControl.ViewMode.Filmstrip;
                        break;
                    case 3:
                        _facadeQueue.View = GUIFacadeControl.ViewMode.LargeIcons;
                        break;
                    case 4:
                        _facadeQueue.View = GUIFacadeControl.ViewMode.SmallIcons;
                        break;
                    case 5:
                        //_facadeQueue.View = GUIFacadeControl.ViewMode.CoverFlow;
                        break;
                }
            }
        }

        #endregion

        #region Load Menus

        /// <summary>
        /// Load the netflix queues
        /// </summary>
        public void LoadQueues()
        {
            _myQueues.Clear();
            _myQueue = new DiscQueue(_user);
            _myQueue.Refresh();
            _myQueues.Add(_myQueue);

            if (_user.CanInstantWatch)
            {
                _myQueue = new InstantQueue(_user);
                _myQueue.Refresh();
                _myQueue.Sort("Title");
                _myQueues.Add(_myQueue);
            }
            else
            {
                _myQueue = new InstantQueue(_user);
                _myQueues.Add(_myQueue);
            }

            _myQueue = new DiscAtHomeQueue(_user);
            _myQueue.Refresh();
            _myQueue.Sort("Title");
            _myQueues.Add(_myQueue);

            _myQueue = new Recommendations(_user);
            _myQueue.Refresh();
            _myQueue.Sort("Title");
            _myQueues.Add(_myQueue);
        }

        /// <summary>
        /// Refresh the netflix queues
        /// </summary>
        public void RefreshQueues()
        {
            _myQueue = new DiscQueue(_user);
            _myQueue.Refresh();
            _myQueues.RemoveAt(0);
            _myQueues.Insert(0, _myQueue);

            if (_user.CanInstantWatch)
            {
                _myQueue = new InstantQueue(_user);
                _myQueue.Refresh();
                _myQueues.RemoveAt(1);
                _myQueue.Sort("Title");
                _myQueues.Insert(1, _myQueue);
            }

            _myQueue = new DiscAtHomeQueue(_user);
            _myQueue.Refresh();
            _myQueues.RemoveAt(2);
            _myQueue.Sort("Title");
            _myQueues.Insert(2, _myQueue);

            _myQueue = new Recommendations(_user);
            _myQueue.Refresh();
            _myQueues.RemoveAt(3);
            _myQueue.Sort("Title"); 
            _myQueues.Insert(3, _myQueue);
        }

        /// <summary>
        /// Clear all the 'hold' queues
        /// </summary>
        public void ClearQueues()
        {
            //----------------------------------------------------------------------------------------------
            // Clear all the queues for the new load
            //----------------------------------------------------------------------------------------------
            _facadeQueue.Clear();
            _facadeQueueHold.Clear();
            _facadeSelectedIndexHold.Clear();
            _facadeSelectedViewHold.Clear();
        }

        /// <summary>
        /// Clear the selections from all the facade items
        /// </summary>
        public void ClearSelections()
        {
            for (int i = 0; i < _facadeQueue.Count; i++)
            {
                if (_facadeQueue[i].Selected)
                    _facadeQueue[i].Selected = false;
            }
        }
        
        /// <summary>
        /// Get the previus queue
        /// </summary>
        public void GetPrevious()
        {
            //----------------------------------------------------------------------------------------------
            // Clear the Queue first
            //----------------------------------------------------------------------------------------------
            _facadeQueue.Clear();

            //----------------------------------------------------------------------------------------------
            // Set the current view
            //----------------------------------------------------------------------------------------------
            _currentView = _facadeSelectedViewHold[_facadeSelectedViewHold.Count - 1];
            SetView(_currentView);

            //----------------------------------------------------------------------------------------------
            // Load the facade control
            //----------------------------------------------------------------------------------------------
            foreach (GUIListItem item in _facadeQueueHold[_facadeQueueHold.Count - 1])
            {
                _facadeQueue.Add(item);
            }
            //----------------------------------------------------------------------------------------------
            // Make sure the previous item is selected
            //----------------------------------------------------------------------------------------------
            _facadeQueue.SelectedListItemIndex = _facadeSelectedIndexHold[_facadeSelectedIndexHold.Count - 1];

            //----------------------------------------------------------------------------------------------
            // Remove the items from the hold
            //----------------------------------------------------------------------------------------------
            _facadeSelectedViewHold.RemoveAt(_facadeSelectedViewHold.Count - 1);
            _facadeSelectedIndexHold.RemoveAt(_facadeSelectedIndexHold.Count - 1);
            _facadeQueueHold.RemoveAt(_facadeQueueHold.Count - 1);

            GUIPropertyManager.SetProperty("#movieof", (_facadeQueue.SelectedListItemIndex + 1).ToString());
            GUIPropertyManager.SetProperty("#moviecount", _facadeQueue.Count.ToString());
            GetCurrentModule();
        }

        /// <summary>
        /// Load the facade control with items in the list
        /// </summary>
        /// <param name="queueItems"></param>
        public void LoadFacadeControlQI(int iSelectedQueue, MyNetFlixMain.FacadeView view)
        {
            SetView(view);

            //----------------------------------------------------------------------------------------
            // Load the queue with QueueItems
            //----------------------------------------------------------------------------------------
            foreach (QueueItem item in _myQueues[iSelectedQueue].QueueItems)
            {
                _facadeQueue.Add(ProcessItem(item, _currentView));
                if (_lstWatchedMovies.Contains(item.CoverId))
                    _facadeQueue[_facadeQueue.Count - 1].IsPlayed = true;
            }
        }

        /// <summary>
        /// Load the facade control with items in the list
        /// </summary>
        /// <param name="queueItems"></param>
        public void LoadFacadeControl(List<QueueItem> queueItems, MyNetFlixMain.FacadeView view)
        {
            SetView(view);

            //----------------------------------------------------------------------------------------
            // Load the queue with QueueItems
            //----------------------------------------------------------------------------------------
            foreach (QueueItem item in queueItems)
            {
                _facadeQueue.Add(ProcessItem(item, _currentView));
                if (_lstWatchedMovies.Contains(item.CoverId))
                   _facadeQueue[_facadeQueue.Count -1].IsPlayed = true;
            }
        }

        /// <summary>
        /// Load the facade control with items in the list
        /// </summary>
        /// <param name="queueItems"></param>
        public void LoadFacadeControl(List<ODataItem> odataItems, MyNetFlixMain.FacadeView view)
        {
            SetView(view);

            //----------------------------------------------------------------------------------------
            // Load the queue with QueueItems
            //----------------------------------------------------------------------------------------
            foreach (ODataItem item in odataItems)
            {
                if(view == MyNetFlixMain.FacadeView.RSS)
                    _facadeQueue.Add(ProcessRSSItem(item, _currentView));
                else
                    _facadeQueue.Add(ProcessItem(item, _currentView));

                if (_lstWatchedMovies.Contains(item.CoverId))
                    _facadeQueue[_facadeQueue.Count - 1].IsPlayed = true;
            }
        }

        /// <summary>
        /// Load the facade control with items in the list
        /// </summary>
        /// <param name="queueItems"></param>
        public void LoadFacadeControl(List<ODataItem> odataItems, Formats.DiscFormat discFormat, SortOrder sortOrder, MyNetFlixMain.FacadeView view)
        {
            SetView(view);
            _myQueue.ODataItems = odataItems;
            _myQueue.SortByDate(discFormat, sortOrder);
            
            //----------------------------------------------------------------------------------------
            // Load the queue with QueueItems
            //----------------------------------------------------------------------------------------
            foreach (ODataItem item in odataItems)
            {
                _facadeQueue.Add(ProcessItem(item, _currentView));
                if (_lstWatchedMovies.Contains(item.CoverId))
                    _facadeQueue[_facadeQueue.Count - 1].IsPlayed = true;
            }
        }

        /// <summary>
        /// Load the History Menu
        /// </summary>
        public void LoadRentalHistoryMenu()
        {
            _facadeQueue.Clear();
            SetView(MyNetFlixMain.FacadeView.Home);
            _facadeQueue.Add(new GUIListItem("All Rental History"));
            _facadeQueue.Add(new GUIListItem("History Returned"));
            _facadeQueue.Add(new GUIListItem("History Shipped"));
            _facadeQueue.Add(new GUIListItem("History Watched"));

            SetFirst((QueueItem)_facadeQueue[0].TVTag, MyNetFlixMain.FacadeView.RentalMenu, false);
        }

        /// <summary>
        /// Load the Main Home Menu
        /// </summary>
        public void LoadUsersMenu()
        {
            _facadeQueueHold.Clear();
            _facadeQueue.Clear();
            SetView(MyNetFlixMain.FacadeView.Home);

            foreach (string menuItem in _queueUsers)
            {
                _facadeQueue.Add(new GUIListItem(menuItem));
            }

            SetFirst((QueueItem)_facadeQueue[0].TVTag, MyNetFlixMain.FacadeView.Users, false);
        }

        /// <summary>
        /// Load the Main Home Menu
        /// </summary>
        public void LoadHomeMenu()
        {
            _facadeQueueHold.Clear();
            _facadeQueue.Clear();
            SetView(MyNetFlixMain.FacadeView.Home);
            _facadeQueue.Add(new GUIListItem("Disc Queue"));
            if (_user.CanInstantWatch)
                _facadeQueue.Add(new GUIListItem("Instant Queue"));
            _facadeQueue.Add(new GUIListItem("Discs At Home"));
            _facadeQueue.Add(new GUIListItem("Recommendations"));
            _facadeQueue.Add(new GUIListItem("Rental History"));

            SetFirst((QueueItem)_facadeQueue[0].TVTag, MyNetFlixMain.FacadeView.Home, false);
        }

        /// <summary>
        /// Load the Main Home Menu
        /// </summary>
        public void LoadInstantUserMenu()
        {
            //--------------------------------------------------------------------------------------------------
            // If there is only one instant user, then ONLY show that user. Otherwise show the list of users
            //--------------------------------------------------------------------------------------------------
            if (_instantUsers.Count > 1)
            {
                SavePrevious(_facadeQueue, _facadeQueue.SelectedListItemIndex, _currentView);
                SetView(MyNetFlixMain.FacadeView.Home);

                foreach (string user in _instantUsers)
                {
                    _facadeQueue.Add(new GUIListItem(user));
                }
                SetFirst((QueueItem)_facadeQueue[0].TVTag, MyNetFlixMain.FacadeView.InstantMenu, false);
            }
            else
            {
                LoadInstantQueue(_instantUsers[0]);
            }
        }

        /// <summary>
        /// Load the instant queue for the specified user
        /// </summary>
        /// <param name="currentUser"></param>
        public void LoadInstantQueue(string currentUser)
        {
            SavePrevious(_facadeQueue, _facadeQueue.SelectedListItemIndex, _currentView);
            List<string> allInstantMovies = _conn.GetAllTitles();
            List<string> myInstantMovies = _conn.GetTitles(_conn.GetInstantUser(currentUser));
            SetView(MyNetFlixMain.FacadeView.InstantDetail);

            //--------------------------------------------------------------------------------
            // Lets load the items directly into the facade control
            //--------------------------------------------------------------------------------
            foreach (QueueItem item in _myQueues[1].QueueItems)
            {
                if (!allInstantMovies.Contains(item.TitleRef))
                {
                    _conn.AddTitle(_conn.GetInstantUser(currentUser), item.TitleRef);
                    myInstantMovies.Add(item.TitleRef);
                }

                if (myInstantMovies.Contains(item.TitleRef))
                {
                    _facadeQueue.Add(ProcessItem(item, _currentView));
                }
            }

            SetFirst((QueueItem)_facadeQueue[0].TVTag, _currentView, true);
        }

        /// <summary>
        /// Load the Season Menu for the title
        /// </summary>
        public void LoadSeasonMenu(string Url)
        {
            Seasons seasons = new Seasons(_user);
            seasons.Refresh(Url);
            SetView(MyNetFlixMain.FacadeView.Season);

            foreach (QueueItem item in seasons.QueueItems)
            {
                if (item.Title.Contains("Season"))
                    item.AltTitle = item.Title.Substring(item.Title.IndexOf("Season"), item.Title.Length - item.Title.IndexOf("Season"));

                _facadeQueue.Add(ProcessItem(item, _currentView));
            }

            SetFirst((QueueItem)_facadeQueue[0].TVTag, _currentView, true);
        }

        #endregion

        #region Context Menus

        /// <summary>
        /// Shows the dialog menu
        /// </summary>
        public void ShowTopXMenu()
        {
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU);
            if (dlg == null)
            {
                return;
            }

            //------------------------------------------------------------------------------------------------
            // Reset the dialog and set the properties, add the heading and menu items.
            //------------------------------------------------------------------------------------------------
            dlg.Reset();
            dlg.SetHeading("NetFlix Top Picks");

            dlg.Add("Top 100");
            dlg.Add("Top 25 by Genre");
            dlg.Add("New Releases");

            //------------------------------------------------------------------------------------------------
            // Show the dialog and wait for the result
            //------------------------------------------------------------------------------------------------
            dlg.DoModal(GetID);
            if (dlg.SelectedId == -1)
            {
                return;
            }

            //--------------------------------------------------------------------------------
            // Since this is a search, lets clear all the prior history
            //--------------------------------------------------------------------------------
            ClearQueues();
            SetView(MyNetFlixMain.FacadeView.RSS);
            RSS rss = new RSS(_user);

            //--------------------------------------------------------------------------------
            // Get the search items from NetFlix
            //--------------------------------------------------------------------------------
            switch (dlg.SelectedId)
            {
                case 1:
                    LoadFacadeControl(rss.GetTop(-1), _currentView);
                    break;
                case 2:
                    ShowGenreOptions();
                    break;
                case 3:
                    LoadFacadeControl(rss.GetTop(-2),_currentView);
                    break;
            }


            //--------------------------------------------------------------------------------
            // Now set the first item and the view
            //--------------------------------------------------------------------------------
            SetFirst((ODataItem)_facadeQueue[0].TVTag, _currentView, true);

            //--------------------------------------------------------------------------------
            // Show the small detail pane
            //--------------------------------------------------------------------------------
            _dummyLabel.Visible = true;
        }

        /// <summary>
        /// Shows the dialog menu
        /// </summary>
        public void ShowGenreOptions()
        {
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU);
            if (dlg == null)
            {
                return;
            }

            //------------------------------------------------------------------------------------------------
            // Reset the dialog and set the properties, add the heading and menu items.
            //------------------------------------------------------------------------------------------------
            dlg.Reset();
            dlg.SetHeading("Genre Options");

            dlg.Add("Action & Adventure");
            dlg.Add("Animation");
            dlg.Add("BluRay");
            dlg.Add("Children & Family");
            dlg.Add("Classics");
            dlg.Add("Comedy");
            dlg.Add("Documentary");
            dlg.Add("Drama");
            dlg.Add("Faith");
            dlg.Add("Foreign");
            dlg.Add("Gay & Lesbian");
            dlg.Add("Horror");
            dlg.Add("Independent");
            dlg.Add("Music");
            dlg.Add("Romance");
            dlg.Add("Sci-Fi");
            dlg.Add("Special");
            dlg.Add("Sports");
            dlg.Add("Television");
            dlg.Add("Thrillers");

            //------------------------------------------------------------------------------------------------
            // Show the dialog and wait for the result
            //------------------------------------------------------------------------------------------------
            dlg.DoModal(GetID);
            if (dlg.SelectedId == -1)
            {
                return;
            }

            RSS rss = new RSS(_user);
            SetView(MyNetFlixMain.FacadeView.RSS);
            LoadFacadeControl(rss.GetTop(dlg.SelectedId), _currentView);
            dlg.PageDestroy();

            //--------------------------------------------------------------------------------
            // Now set the first item and the view
            //--------------------------------------------------------------------------------
            SetFirst((ODataItem)_facadeQueue[0].TVTag, _currentView, true);

            //--------------------------------------------------------------------------------
            // Show the small detail pane
            //--------------------------------------------------------------------------------
            _dummyLabel.Visible = true;
        }

        /// <summary>
        /// Shows the dialog menu
        /// </summary>
        public void ShowSearchGenreOptions(ref string sGenre)
        {
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU);
            if (dlg == null)
            {
                return;
            }

            //------------------------------------------------------------------------------------------------
            // Reset the dialog and set the properties, add the heading and menu items.
            //------------------------------------------------------------------------------------------------
            dlg.Reset();
            dlg.SetHeading("Genre Options");

            dlg.Add("Action & Adventure");
            dlg.Add("Animation");
            dlg.Add("BluRay");
            dlg.Add("Children & Family");
            dlg.Add("Classics");
            dlg.Add("Comedy");
            dlg.Add("Documentary");
            dlg.Add("Drama");
            dlg.Add("Faith");
            dlg.Add("Foreign");
            dlg.Add("Gay & Lesbian");
            dlg.Add("Horror");
            dlg.Add("Independent");
            dlg.Add("Music");
            dlg.Add("Romance");
            dlg.Add("Sci-Fi");
            dlg.Add("Special");
            dlg.Add("Sports");
            dlg.Add("Television");
            dlg.Add("Thrillers");

            //------------------------------------------------------------------------------------------------
            // Show the dialog and wait for the result
            //------------------------------------------------------------------------------------------------
            dlg.DoModal(GetID);
            if (dlg.SelectedId == -1)
            {
                return;
            }

            sGenre = dlg.SelectedLabelText;
        }

        /// <summary>
        /// Shows the dialog menu
        /// </summary>
        public void ShowNewReleaseMenu()
        {
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU);
            if (dlg == null)
            {
                return;
            }

            //------------------------------------------------------------------------------------------------
            // Reset the dialog and set the properties, add the heading and menu items.
            //------------------------------------------------------------------------------------------------
            dlg.Reset();
            dlg.SetHeading("New Releases");

            dlg.Add("DVD");
            dlg.Add("BluRay");
            dlg.Add("Instant View");
            dlg.Add("Instant View (TV Series)");


            //------------------------------------------------------------------------------------------------
            // Show the dialog and wait for the result
            //------------------------------------------------------------------------------------------------
            dlg.DoModal(GetID);
            if (dlg.SelectedId == -1)
            {
                return;
            }

            //--------------------------------------------------------------------------------
            // Since this is a search, lets clear all the prior history
            //--------------------------------------------------------------------------------
            ClearQueues();
            SetView(MyNetFlixMain.FacadeView.OData);

            //--------------------------------------------------------------------------------
            // Get the search items from NetFlix and load the Facade Control
            //--------------------------------------------------------------------------------
            Search search = new Search(_user);
            switch (dlg.SelectedId)
            {
                case 1:
                    LoadFacadeControl(search.Refresh("NewDVD", Formats.DiscFormat.DVD), Formats.DiscFormat.DVD, SortOrder.Descending, _currentView);
                    break;
                case 2:
                    LoadFacadeControl(search.Refresh("NewBluRay", Formats.DiscFormat.BluRay), Formats.DiscFormat.BluRay, SortOrder.Descending, _currentView);
                    break;
                case 3:
                    LoadFacadeControl(search.Refresh("NewInstant", Formats.DiscFormat.Instant), Formats.DiscFormat.Instant, SortOrder.Descending, _currentView);
                    break;
                case 4:
                    LoadFacadeControl(search.Refresh("NewTelevision", Formats.DiscFormat.Instant), Formats.DiscFormat.Instant, SortOrder.Descending, _currentView);
                    break;
            }

            //--------------------------------------------------------------------------------
            // Now set the first item and the view
            //--------------------------------------------------------------------------------
            SetFirst((ODataItem)_facadeQueue[0].TVTag, _currentView, true);

            //--------------------------------------------------------------------------------
            // Show the small detail pane
            //--------------------------------------------------------------------------------
            _dummyLabel.Visible = true;
        }

        /// <summary>
        /// Shows the dialog menu
        /// </summary>
        public void ShowUpcomingReleaseMenu()
        {
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU);
            if (dlg == null)
            {
                return;
            }

            //------------------------------------------------------------------------------------------------
            // Reset the dialog and set the properties, add the heading and menu items.
            //------------------------------------------------------------------------------------------------
            dlg.Reset();
            dlg.SetHeading("Upcoming Releases");

            dlg.Add("DVD");
            dlg.Add("BluRay");
            dlg.Add("Instant View");
            dlg.Add("Instant View (TV Series)");


            //------------------------------------------------------------------------------------------------
            // Show the dialog and wait for the result
            //------------------------------------------------------------------------------------------------
            dlg.DoModal(GetID);
            if (dlg.SelectedId == -1)
            {
                return;
            }

            //--------------------------------------------------------------------------------
            // Since this is a search, lets clear all the prior history
            //--------------------------------------------------------------------------------
            ClearQueues();
            SetView(MyNetFlixMain.FacadeView.OData);

            //--------------------------------------------------------------------------------
            // Get the search items from NetFlix and load the Facade Control
            //--------------------------------------------------------------------------------
            Search search = new Search(_user);
            switch (dlg.SelectedId)
            {
                case 1:
                    LoadFacadeControl(search.Refresh("UpcomingDVD", Formats.DiscFormat.DVD), Formats.DiscFormat.DVD, SortOrder.Ascending, _currentView);
                    break;
                case 2:
                    LoadFacadeControl(search.Refresh("UpcomingBluRay", Formats.DiscFormat.BluRay), Formats.DiscFormat.BluRay, SortOrder.Ascending, _currentView);
                    break;
                case 3:
                    LoadFacadeControl(search.Refresh("UpcomingInstant", Formats.DiscFormat.Instant), Formats.DiscFormat.Instant, SortOrder.Ascending, _currentView);
                    break;
                case 4:
                    LoadFacadeControl(search.Refresh("UpcomingTelevision", Formats.DiscFormat.Instant), Formats.DiscFormat.Instant, SortOrder.Ascending, _currentView);
                    break;
            }

            //--------------------------------------------------------------------------------
            // Now set the first item and the view
            //--------------------------------------------------------------------------------
            SetFirst((ODataItem)_facadeQueue[0].TVTag, _currentView, true);

            //--------------------------------------------------------------------------------
            // Show the small detail pane
            //--------------------------------------------------------------------------------
            _dummyLabel.Visible = true;
        }

        /// <summary>
        /// Shows the dialog menu
        /// </summary>
        public void ShowViewMenu()
        {
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU);

            if (dlg == null)
            {
                return;
            }

            //------------------------------------------------------------------------------------------------
            // Reset the dialog and set the properties, add the heading and menu items.
            //------------------------------------------------------------------------------------------------
            dlg.Reset();
            dlg.SetHeading("Toggle View");

            dlg.Add("List");
            dlg.Add("Film Strip");
            dlg.Add("Large Icons");
            dlg.Add("Small Icons");
            dlg.Add("CoverArt");

            //------------------------------------------------------------------------------------------------
            // Show the dialog and wait for the result
            //------------------------------------------------------------------------------------------------
            dlg.DoModal(GetID);
            if (dlg.SelectedId == -1)
            {
                return;
            }
            //-------------------------------------------------------------------------------------------------------
            // Lets clear the queue before we write anything to it...
            //-------------------------------------------------------------------------------------------------------
            try
            {
                SavePrevious(_facadeQueue, _facadeQueue.SelectedListItemIndex, _currentView);

                switch (dlg.SelectedId)
                {
                    case 1:
                        _facadeQueue.View = GUIFacadeControl.ViewMode.List;
                        break;
                    case 2:
                        _facadeQueue.View = GUIFacadeControl.ViewMode.Filmstrip;
                        break;
                    case 3:
                        _facadeQueue.View = GUIFacadeControl.ViewMode.LargeIcons;
                        break;
                    case 4:
                        _facadeQueue.View = GUIFacadeControl.ViewMode.SmallIcons;
                        break;
                    case 5:
                        //_facadeQueue.View = GUIFacadeControl.ViewMode.CoverFlow;
                        break;
                }
                _conn.AddMyView(dlg.SelectedId, _currentView);

                GetPrevious();

            }
            catch { }
        }

        /// <summary>
        /// Shows the dialog menu
        /// </summary>
        public int ShowSearchOptions()
        {
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU);
            if (dlg == null)
            {
                return -1;
            }

            //------------------------------------------------------------------------------------------------
            // Reset the dialog and set the properties, add the heading and menu items.
            //------------------------------------------------------------------------------------------------
            dlg.Reset();
            dlg.SetHeading("Search Options");

            dlg.Add("All Title Search");
            dlg.Add("Instant Search by Title");
            dlg.Add("Instant Search by Title (TV Series)");
            dlg.Add("Instant Search by Genre");
            dlg.Add("People Search");

            //------------------------------------------------------------------------------------------------
            // Show the dialog and wait for the result
            //------------------------------------------------------------------------------------------------
            dlg.DoModal(GetID);
            if (dlg.SelectedId == -1)
            {
                return -1;
            }
            return dlg.SelectedId;
        }

        /// <summary>
        /// Gets the input from the virtual keyboard window
        /// </summary>
        /// <param name="strLine"></param>
        public void GetStringFromKeyboard(ref string strLine)
        {
            VirtualKeyboard keyboard = (VirtualKeyboard)GUIWindowManager.GetWindow((int)Window.WINDOW_VIRTUAL_KEYBOARD);

            if (null == keyboard)
            {
                return;
            }

            keyboard.Reset();
            keyboard.Text = strLine;
            keyboard.DoModal(GetID);

            if (keyboard.IsConfirmed)
            {
                strLine = keyboard.Text;
            }
        }


        #endregion
    }
}
